use crate::rpc::pb::system::system_service_server::SystemService;
use crate::rpc::service::ServiceManager;
use sea_orm::DatabaseConnection;
use tonic::async_trait;

// 导入所有需要的类型
use crate::rpc::pb::{
    auth::*, dept::*, menu::*, oauth::*, permission::*, post::*, role::*, user::*,
};

/// 系统服务gRPC实现
#[derive(Clone)]
pub struct ServiceImpl {
    /// 服务管理器 - 统一管理所有业务服务
    pub services: ServiceManager,
}

impl ServiceImpl {
    pub fn new(db: DatabaseConnection) -> Self {
        Self {
            services: ServiceManager::new(db),
        }
    }
}

#[async_trait]
impl SystemService for ServiceImpl {
    // ===== 认证相关服务 =====
    async fn get_captcha(
        &self,
        request: tonic::Request<GetCaptchaReq>,
    ) -> Result<tonic::Response<GetCaptchaResp>, tonic::Status> {
        self.services.auth.get_captcha(request).await
    }

    async fn login_by_account(
        &self,
        request: tonic::Request<LoginByAccountReq>,
    ) -> Result<tonic::Response<LoginByAccountResp>, tonic::Status> {
        self.services.auth.login_by_account(request).await
    }

    async fn login_by_account_encrypt(
        &self,
        request: tonic::Request<LoginByAccountEncryptReq>,
    ) -> Result<tonic::Response<LoginByAccountEncryptResp>, tonic::Status> {
        self.services.auth.login_by_account_encrypt(request).await
    }

    async fn register_by_account(
        &self,
        request: tonic::Request<RegisterByAccountReq>,
    ) -> Result<tonic::Response<RegisterByAccountResp>, tonic::Status> {
        self.services.auth.register_by_account(request).await
    }

    async fn login_by_mobile(
        &self,
        request: tonic::Request<LoginByMobileReq>,
    ) -> Result<tonic::Response<LoginByMobileResp>, tonic::Status> {
        self.services.auth.login_by_mobile(request).await
    }

    async fn login_by_email(
        &self,
        request: tonic::Request<LoginByEmailReq>,
    ) -> Result<tonic::Response<LoginByEmailResp>, tonic::Status> {
        self.services.auth.login_by_email(request).await
    }

    async fn login_by_code2_session(
        &self,
        request: tonic::Request<LoginByCode2SessionReq>,
    ) -> Result<tonic::Response<LoginByCode2SessionResp>, tonic::Status> {
        self.services.auth.login_by_code2_session(request).await
    }

    async fn login_by_mini_program(
        &self,
        request: tonic::Request<LoginByMiniProgramReq>,
    ) -> Result<tonic::Response<LoginByMiniProgramResp>, tonic::Status> {
        self.services.auth.login_by_mini_program(request).await
    }

    async fn verify_token(
        &self,
        request: tonic::Request<VerifyTokenReq>,
    ) -> Result<tonic::Response<VerifyTokenResp>, tonic::Status> {
        self.services.auth.verify_token(request).await
    }

    async fn refresh_token(
        &self,
        request: tonic::Request<RefreshTokenReq>,
    ) -> Result<tonic::Response<RefreshTokenResp>, tonic::Status> {
        self.services.auth.refresh_token(request).await
    }

    async fn logout(
        &self,
        request: tonic::Request<LogoutReq>,
    ) -> Result<tonic::Response<LogoutResp>, tonic::Status> {
        self.services.auth.logout(request).await
    }

    async fn unregister(
        &self,
        request: tonic::Request<UnregisterReq>,
    ) -> Result<tonic::Response<UnregisterResp>, tonic::Status> {
        self.services.auth.unregister(request).await
    }

    // ===== 用户管理服务 =====
    async fn get_user_page(
        &self,
        request: tonic::Request<GetUserPageReq>,
    ) -> Result<tonic::Response<GetUserPageRes>, tonic::Status> {
        self.services.user.get_user_page(request).await
    }

    async fn get_user_info(
        &self,
        request: tonic::Request<GetUserInfoReq>,
    ) -> Result<tonic::Response<GetUserInfoRes>, tonic::Status> {
        self.services.user.get_user_info(request).await
    }

    async fn create_user(
        &self,
        request: tonic::Request<CreateUserReq>,
    ) -> Result<tonic::Response<CreateUserRes>, tonic::Status> {
        self.services.user.create_user(request).await
    }

    async fn update_user(
        &self,
        request: tonic::Request<UpdateUserReq>,
    ) -> Result<tonic::Response<UpdateUserRes>, tonic::Status> {
        self.services.user.update_user(request).await
    }

    async fn delete_user(
        &self,
        request: tonic::Request<DeleteUserReq>,
    ) -> Result<tonic::Response<DeleteUserRes>, tonic::Status> {
        self.services.user.delete_user(request).await
    }

    async fn update_user_password(
        &self,
        request: tonic::Request<UpdateUserPasswordReq>,
    ) -> Result<tonic::Response<UpdateUserPasswordRes>, tonic::Status> {
        self.services.user.update_user_password(request).await
    }

    async fn reset_user_password(
        &self,
        request: tonic::Request<ResetUserPasswordReq>,
    ) -> Result<tonic::Response<ResetUserPasswordRes>, tonic::Status> {
        self.services.user.reset_user_password(request).await
    }

    async fn update_user_profile(
        &self,
        request: tonic::Request<UpdateUserProfileReq>,
    ) -> Result<tonic::Response<UpdateUserProfileRes>, tonic::Status> {
        self.services.user.update_user_profile(request).await
    }

    // ===== 角色管理服务 =====
    async fn get_role_list(
        &self,
        request: tonic::Request<GetRoleListReq>,
    ) -> Result<tonic::Response<GetRoleListRes>, tonic::Status> {
        self.services.role.get_role_list(request).await
    }

    async fn get_role_info(
        &self,
        request: tonic::Request<GetRoleInfoReq>,
    ) -> Result<tonic::Response<GetRoleInfoRes>, tonic::Status> {
        self.services.role.get_role_info(request).await
    }

    async fn create_role(
        &self,
        request: tonic::Request<CreateRoleReq>,
    ) -> Result<tonic::Response<CreateRoleRes>, tonic::Status> {
        self.services.role.create_role(request).await
    }

    async fn update_role(
        &self,
        request: tonic::Request<UpdateRoleReq>,
    ) -> Result<tonic::Response<UpdateRoleRes>, tonic::Status> {
        self.services.role.update_role(request).await
    }

    async fn delete_role(
        &self,
        request: tonic::Request<DeleteRoleReq>,
    ) -> Result<tonic::Response<DeleteRoleRes>, tonic::Status> {
        self.services.role.delete_role(request).await
    }

    async fn bind_roles_by_user_id(
        &self,
        request: tonic::Request<BindRolesByUserIdReq>,
    ) -> Result<tonic::Response<BindRolesByUserIdRes>, tonic::Status> {
        self.services.role.bind_roles_by_user_id(request).await
    }

    async fn get_role_tree(
        &self,
        request: tonic::Request<GetRoleTreeReq>,
    ) -> Result<tonic::Response<GetRoleTreeRes>, tonic::Status> {
        self.services.role.get_role_tree(request).await
    }

    // ===== 菜单管理服务 =====
    async fn get_menu_list(
        &self,
        request: tonic::Request<GetMenuListReq>,
    ) -> Result<tonic::Response<GetMenuListRes>, tonic::Status> {
        self.services.menu.get_menu_list(request).await
    }

    async fn get_menu_info(
        &self,
        request: tonic::Request<GetMenuInfoReq>,
    ) -> Result<tonic::Response<GetMenuInfoRes>, tonic::Status> {
        self.services.menu.get_menu_info(request).await
    }

    async fn create_menu(
        &self,
        request: tonic::Request<CreateMenuReq>,
    ) -> Result<tonic::Response<CreateMenuRes>, tonic::Status> {
        self.services.menu.create_menu(request).await
    }

    async fn update_menu(
        &self,
        request: tonic::Request<UpdateMenuReq>,
    ) -> Result<tonic::Response<UpdateMenuRes>, tonic::Status> {
        self.services.menu.update_menu(request).await
    }

    async fn delete_menu(
        &self,
        request: tonic::Request<DeleteMenuReq>,
    ) -> Result<tonic::Response<DeleteMenuRes>, tonic::Status> {
        self.services.menu.delete_menu(request).await
    }

    async fn get_user_menu(
        &self,
        request: tonic::Request<GetUserMenuReq>,
    ) -> Result<tonic::Response<GetUserMenuRes>, tonic::Status> {
        self.services.menu.get_user_menu(request).await
    }

    // ===== 部门管理服务 =====
    async fn get_dept_list(
        &self,
        request: tonic::Request<GetDeptListReq>,
    ) -> Result<tonic::Response<GetDeptListRes>, tonic::Status> {
        self.services.dept.get_dept_list(request).await
    }

    async fn get_dept_info(
        &self,
        request: tonic::Request<GetDeptInfoReq>,
    ) -> Result<tonic::Response<GetDeptInfoRes>, tonic::Status> {
        self.services.dept.get_dept_info(request).await
    }

    async fn create_dept(
        &self,
        request: tonic::Request<CreateDeptReq>,
    ) -> Result<tonic::Response<CreateDeptRes>, tonic::Status> {
        self.services.dept.create_dept(request).await
    }

    async fn update_dept(
        &self,
        request: tonic::Request<UpdateDeptReq>,
    ) -> Result<tonic::Response<UpdateDeptRes>, tonic::Status> {
        self.services.dept.update_dept(request).await
    }

    async fn delete_dept(
        &self,
        request: tonic::Request<DeleteDeptReq>,
    ) -> Result<tonic::Response<DeleteDeptRes>, tonic::Status> {
        self.services.dept.delete_dept(request).await
    }

    async fn get_dept_tree(
        &self,
        request: tonic::Request<GetDeptTreeReq>,
    ) -> Result<tonic::Response<GetDeptTreeRes>, tonic::Status> {
        self.services.dept.get_dept_tree(request).await
    }

    // ===== 岗位管理服务 =====
    async fn get_post_list(
        &self,
        request: tonic::Request<GetPostListReq>,
    ) -> Result<tonic::Response<GetPostListRes>, tonic::Status> {
        self.services.post.get_post_list(request).await
    }

    async fn get_post_info(
        &self,
        request: tonic::Request<GetPostInfoReq>,
    ) -> Result<tonic::Response<GetPostInfoRes>, tonic::Status> {
        self.services.post.get_post_info(request).await
    }

    async fn create_post(
        &self,
        request: tonic::Request<CreatePostReq>,
    ) -> Result<tonic::Response<CreatePostRes>, tonic::Status> {
        self.services.post.create_post(request).await
    }

    async fn update_post(
        &self,
        request: tonic::Request<UpdatePostReq>,
    ) -> Result<tonic::Response<UpdatePostRes>, tonic::Status> {
        self.services.post.update_post(request).await
    }

    async fn delete_post(
        &self,
        request: tonic::Request<DeletePostReq>,
    ) -> Result<tonic::Response<DeletePostRes>, tonic::Status> {
        self.services.post.delete_post(request).await
    }

    async fn bind_posts_by_user_id(
        &self,
        request: tonic::Request<BindPostsByUserIdReq>,
    ) -> Result<tonic::Response<BindPostsByUserIdRes>, tonic::Status> {
        self.services.post.bind_posts_by_user_id(request).await
    }

    // ===== 权限管理服务 =====
    async fn check_permission(
        &self,
        request: tonic::Request<CheckPermissionReq>,
    ) -> Result<tonic::Response<CheckPermissionRes>, tonic::Status> {
        self.services.permission.check_permission(request).await
    }

    async fn get_user_permissions(
        &self,
        request: tonic::Request<GetUserPermissionsReq>,
    ) -> Result<tonic::Response<GetUserPermissionsRes>, tonic::Status> {
        self.services.permission.get_user_permissions(request).await
    }

    async fn get_role_permissions(
        &self,
        request: tonic::Request<GetRolePermissionsReq>,
    ) -> Result<tonic::Response<GetRolePermissionsRes>, tonic::Status> {
        self.services.permission.get_role_permissions(request).await
    }

    async fn add_policy(
        &self,
        request: tonic::Request<AddPolicyReq>,
    ) -> Result<tonic::Response<AddPolicyRes>, tonic::Status> {
        self.services.permission.add_policy(request).await
    }

    async fn remove_policy(
        &self,
        request: tonic::Request<RemovePolicyReq>,
    ) -> Result<tonic::Response<RemovePolicyRes>, tonic::Status> {
        self.services.permission.remove_policy(request).await
    }

    async fn get_policy_list(
        &self,
        request: tonic::Request<GetPolicyListReq>,
    ) -> Result<tonic::Response<GetPolicyListRes>, tonic::Status> {
        self.services.permission.get_policy_list(request).await
    }

    // ===== OAuth管理服务 =====
    async fn get_oauth_list(
        &self,
        request: tonic::Request<GetOauthListReq>,
    ) -> Result<tonic::Response<GetOauthListRes>, tonic::Status> {
        self.services.oauth.get_oauth_list(request).await
    }

    async fn get_oauth_info(
        &self,
        request: tonic::Request<GetOauthInfoReq>,
    ) -> Result<tonic::Response<GetOauthInfoRes>, tonic::Status> {
        self.services.oauth.get_oauth_info(request).await
    }

    async fn create_oauth(
        &self,
        request: tonic::Request<CreateOauthReq>,
    ) -> Result<tonic::Response<CreateOauthRes>, tonic::Status> {
        self.services.oauth.create_oauth(request).await
    }

    async fn update_oauth(
        &self,
        request: tonic::Request<UpdateOauthReq>,
    ) -> Result<tonic::Response<UpdateOauthRes>, tonic::Status> {
        self.services.oauth.update_oauth(request).await
    }

    async fn delete_oauth(
        &self,
        request: tonic::Request<DeleteOauthReq>,
    ) -> Result<tonic::Response<DeleteOauthRes>, tonic::Status> {
        self.services.oauth.delete_oauth(request).await
    }

    async fn get_oauth_provider(
        &self,
        request: tonic::Request<GetOauthProviderReq>,
    ) -> Result<tonic::Response<GetOauthProviderRes>, tonic::Status> {
        self.services.oauth.get_oauth_provider(request).await
    }

    async fn get_user_bind_account(
        &self,
        request: tonic::Request<GetUserBindAccountReq>,
    ) -> Result<tonic::Response<GetUserBindAccountRes>, tonic::Status> {
        self.services.oauth.get_user_bind_account(request).await
    }

    async fn bind_account(
        &self,
        request: tonic::Request<BindAccountReq>,
    ) -> Result<tonic::Response<BindAccountRes>, tonic::Status> {
        self.services.oauth.bind_account(request).await
    }

    async fn unbind_account(
        &self,
        request: tonic::Request<UnbindAccountReq>,
    ) -> Result<tonic::Response<UnbindAccountRes>, tonic::Status> {
        self.services.oauth.unbind_account(request).await
    }

    async fn find_user_by_oauth(
        &self,
        request: tonic::Request<FindUserByOauthReq>,
    ) -> Result<tonic::Response<FindUserByOauthRes>, tonic::Status> {
        self.services.oauth.find_user_by_oauth(request).await
    }
}

/// 生成客户端方法的宏
#[macro_export]
macro_rules! impl_client_methods {
    () => {
        // ===== 认证相关方法 =====
        pub async fn get_captcha(
            &self,
            req: GetCaptchaReq,
        ) -> Result<tonic::Response<GetCaptchaResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_captcha(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_account(
            &self,
            req: LoginByAccountReq,
        ) -> Result<tonic::Response<LoginByAccountResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_account(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_account_encrypt(
            &self,
            req: LoginByAccountEncryptReq,
        ) -> Result<tonic::Response<LoginByAccountEncryptResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_account_encrypt(request).await },
                req,
            )
            .await
        }

        pub async fn register_by_account(
            &self,
            req: RegisterByAccountReq,
        ) -> Result<tonic::Response<RegisterByAccountResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.register_by_account(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_mobile(
            &self,
            req: LoginByMobileReq,
        ) -> Result<tonic::Response<LoginByMobileResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_mobile(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_email(
            &self,
            req: LoginByEmailReq,
        ) -> Result<tonic::Response<LoginByEmailResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_email(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_code2_session(
            &self,
            req: LoginByCode2SessionReq,
        ) -> Result<tonic::Response<LoginByCode2SessionResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_code2_session(request).await },
                req,
            )
            .await
        }

        pub async fn login_by_mini_program(
            &self,
            req: LoginByMiniProgramReq,
        ) -> Result<tonic::Response<LoginByMiniProgramResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.login_by_mini_program(request).await },
                req,
            )
            .await
        }

        pub async fn verify_token(
            &self,
            req: VerifyTokenReq,
        ) -> Result<tonic::Response<VerifyTokenResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.verify_token(request).await },
                req,
            )
            .await
        }

        pub async fn refresh_token(
            &self,
            req: RefreshTokenReq,
        ) -> Result<tonic::Response<RefreshTokenResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.refresh_token(request).await },
                req,
            )
            .await
        }

        pub async fn logout(
            &self,
            req: LogoutReq,
        ) -> Result<tonic::Response<LogoutResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.logout(request).await },
                req,
            )
            .await
        }

        pub async fn unregister(
            &self,
            req: UnregisterReq,
        ) -> Result<tonic::Response<UnregisterResp>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.unregister(request).await },
                req,
            )
            .await
        }

        // ===== 用户管理方法 =====
        pub async fn get_user_page(
            &self,
            req: GetUserPageReq,
        ) -> Result<tonic::Response<GetUserPageRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_user_page(request).await },
                req,
            )
            .await
        }

        pub async fn get_user_info(
            &self,
            req: GetUserInfoReq,
        ) -> Result<tonic::Response<GetUserInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_user_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_user(
            &self,
            req: CreateUserReq,
        ) -> Result<tonic::Response<CreateUserRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_user(request).await },
                req,
            )
            .await
        }

        pub async fn update_user(
            &self,
            req: UpdateUserReq,
        ) -> Result<tonic::Response<UpdateUserRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_user(request).await },
                req,
            )
            .await
        }

        pub async fn delete_user(
            &self,
            req: DeleteUserReq,
        ) -> Result<tonic::Response<DeleteUserRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_user(request).await },
                req,
            )
            .await
        }

        pub async fn update_user_password(
            &self,
            req: UpdateUserPasswordReq,
        ) -> Result<tonic::Response<UpdateUserPasswordRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_user_password(request).await },
                req,
            )
            .await
        }

        pub async fn reset_user_password(
            &self,
            req: ResetUserPasswordReq,
        ) -> Result<tonic::Response<ResetUserPasswordRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.reset_user_password(request).await },
                req,
            )
            .await
        }

        pub async fn update_user_profile(
            &self,
            req: UpdateUserProfileReq,
        ) -> Result<tonic::Response<UpdateUserProfileRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_user_profile(request).await },
                req,
            )
            .await
        }

        // ===== 角色管理方法 =====
        pub async fn get_role_list(
            &self,
            req: GetRoleListReq,
        ) -> Result<tonic::Response<GetRoleListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_role_list(request).await },
                req,
            )
            .await
        }

        pub async fn get_role_info(
            &self,
            req: GetRoleInfoReq,
        ) -> Result<tonic::Response<GetRoleInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_role_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_role(
            &self,
            req: CreateRoleReq,
        ) -> Result<tonic::Response<CreateRoleRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_role(request).await },
                req,
            )
            .await
        }

        pub async fn update_role(
            &self,
            req: UpdateRoleReq,
        ) -> Result<tonic::Response<UpdateRoleRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_role(request).await },
                req,
            )
            .await
        }

        pub async fn delete_role(
            &self,
            req: DeleteRoleReq,
        ) -> Result<tonic::Response<DeleteRoleRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_role(request).await },
                req,
            )
            .await
        }

        pub async fn bind_roles_by_user_id(
            &self,
            req: BindRolesByUserIdReq,
        ) -> Result<tonic::Response<BindRolesByUserIdRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.bind_roles_by_user_id(request).await },
                req,
            )
            .await
        }

        pub async fn get_role_tree(
            &self,
            req: GetRoleTreeReq,
        ) -> Result<tonic::Response<GetRoleTreeRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_role_tree(request).await },
                req,
            )
            .await
        }

        // ===== 菜单管理方法 =====
        pub async fn get_menu_list(
            &self,
            req: GetMenuListReq,
        ) -> Result<tonic::Response<GetMenuListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_menu_list(request).await },
                req,
            )
            .await
        }

        pub async fn get_menu_info(
            &self,
            req: GetMenuInfoReq,
        ) -> Result<tonic::Response<GetMenuInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_menu_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_menu(
            &self,
            req: CreateMenuReq,
        ) -> Result<tonic::Response<CreateMenuRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_menu(request).await },
                req,
            )
            .await
        }

        pub async fn update_menu(
            &self,
            req: UpdateMenuReq,
        ) -> Result<tonic::Response<UpdateMenuRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_menu(request).await },
                req,
            )
            .await
        }

        pub async fn delete_menu(
            &self,
            req: DeleteMenuReq,
        ) -> Result<tonic::Response<DeleteMenuRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_menu(request).await },
                req,
            )
            .await
        }

        pub async fn get_user_menu(
            &self,
            req: GetUserMenuReq,
        ) -> Result<tonic::Response<GetUserMenuRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_user_menu(request).await },
                req,
            )
            .await
        }

        // ===== 部门管理方法 =====
        pub async fn get_dept_list(
            &self,
            req: GetDeptListReq,
        ) -> Result<tonic::Response<GetDeptListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_dept_list(request).await },
                req,
            )
            .await
        }

        pub async fn get_dept_info(
            &self,
            req: GetDeptInfoReq,
        ) -> Result<tonic::Response<GetDeptInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_dept_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_dept(
            &self,
            req: CreateDeptReq,
        ) -> Result<tonic::Response<CreateDeptRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_dept(request).await },
                req,
            )
            .await
        }

        pub async fn update_dept(
            &self,
            req: UpdateDeptReq,
        ) -> Result<tonic::Response<UpdateDeptRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_dept(request).await },
                req,
            )
            .await
        }

        pub async fn delete_dept(
            &self,
            req: DeleteDeptReq,
        ) -> Result<tonic::Response<DeleteDeptRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_dept(request).await },
                req,
            )
            .await
        }

        pub async fn get_dept_tree(
            &self,
            req: GetDeptTreeReq,
        ) -> Result<tonic::Response<GetDeptTreeRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_dept_tree(request).await },
                req,
            )
            .await
        }

        // ===== 岗位管理方法 =====
        pub async fn get_post_list(
            &self,
            req: GetPostListReq,
        ) -> Result<tonic::Response<GetPostListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_post_list(request).await },
                req,
            )
            .await
        }

        pub async fn get_post_info(
            &self,
            req: GetPostInfoReq,
        ) -> Result<tonic::Response<GetPostInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_post_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_post(
            &self,
            req: CreatePostReq,
        ) -> Result<tonic::Response<CreatePostRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_post(request).await },
                req,
            )
            .await
        }

        pub async fn update_post(
            &self,
            req: UpdatePostReq,
        ) -> Result<tonic::Response<UpdatePostRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_post(request).await },
                req,
            )
            .await
        }

        pub async fn delete_post(
            &self,
            req: DeletePostReq,
        ) -> Result<tonic::Response<DeletePostRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_post(request).await },
                req,
            )
            .await
        }

        pub async fn bind_posts_by_user_id(
            &self,
            req: BindPostsByUserIdReq,
        ) -> Result<tonic::Response<BindPostsByUserIdRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.bind_posts_by_user_id(request).await },
                req,
            )
            .await
        }

        // ===== 权限管理方法 =====
        pub async fn check_permission(
            &self,
            req: CheckPermissionReq,
        ) -> Result<tonic::Response<CheckPermissionRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.check_permission(request).await },
                req,
            )
            .await
        }

        pub async fn get_user_permissions(
            &self,
            req: GetUserPermissionsReq,
        ) -> Result<tonic::Response<GetUserPermissionsRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_user_permissions(request).await },
                req,
            )
            .await
        }

        pub async fn get_role_permissions(
            &self,
            req: GetRolePermissionsReq,
        ) -> Result<tonic::Response<GetRolePermissionsRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_role_permissions(request).await },
                req,
            )
            .await
        }

        pub async fn add_policy(
            &self,
            req: AddPolicyReq,
        ) -> Result<tonic::Response<AddPolicyRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.add_policy(request).await },
                req,
            )
            .await
        }

        pub async fn remove_policy(
            &self,
            req: RemovePolicyReq,
        ) -> Result<tonic::Response<RemovePolicyRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.remove_policy(request).await },
                req,
            )
            .await
        }

        pub async fn get_policy_list(
            &self,
            req: GetPolicyListReq,
        ) -> Result<tonic::Response<GetPolicyListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_policy_list(request).await },
                req,
            )
            .await
        }

        // ===== OAuth管理方法 =====
        pub async fn get_oauth_list(
            &self,
            req: GetOauthListReq,
        ) -> Result<tonic::Response<GetOauthListRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_oauth_list(request).await },
                req,
            )
            .await
        }

        pub async fn get_oauth_info(
            &self,
            req: GetOauthInfoReq,
        ) -> Result<tonic::Response<GetOauthInfoRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_oauth_info(request).await },
                req,
            )
            .await
        }

        pub async fn create_oauth(
            &self,
            req: CreateOauthReq,
        ) -> Result<tonic::Response<CreateOauthRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.create_oauth(request).await },
                req,
            )
            .await
        }

        pub async fn update_oauth(
            &self,
            req: UpdateOauthReq,
        ) -> Result<tonic::Response<UpdateOauthRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.update_oauth(request).await },
                req,
            )
            .await
        }

        pub async fn delete_oauth(
            &self,
            req: DeleteOauthReq,
        ) -> Result<tonic::Response<DeleteOauthRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.delete_oauth(request).await },
                req,
            )
            .await
        }

        pub async fn get_oauth_provider(
            &self,
            req: GetOauthProviderReq,
        ) -> Result<tonic::Response<GetOauthProviderRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_oauth_provider(request).await },
                req,
            )
            .await
        }

        pub async fn get_user_bind_account(
            &self,
            req: GetUserBindAccountReq,
        ) -> Result<tonic::Response<GetUserBindAccountRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.get_user_bind_account(request).await },
                req,
            )
            .await
        }

        pub async fn bind_account(
            &self,
            req: BindAccountReq,
        ) -> Result<tonic::Response<BindAccountRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.bind_account(request).await },
                req,
            )
            .await
        }

        pub async fn unbind_account(
            &self,
            req: UnbindAccountReq,
        ) -> Result<tonic::Response<UnbindAccountRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.unbind_account(request).await },
                req,
            )
            .await
        }

        pub async fn find_user_by_oauth(
            &self,
            req: FindUserByOauthReq,
        ) -> Result<tonic::Response<FindUserByOauthRes>, tonic::Status> {
            self.call_rpc(
                |mut client, request| async move { client.find_user_by_oauth(request).await },
                req,
            )
            .await
        }
    };
}
